package sample.handler;

import org.springframework.lang.Nullable;
import org.springframework.messaging.simp.stomp.*;

import java.lang.reflect.Type;
import java.util.concurrent.CountDownLatch;

/**
 * websocket stomp 协议
 */
public class CustomStompSessionHandler extends StompSessionHandlerAdapter {
    private CountDownLatch latch;

    public CustomStompSessionHandler(CountDownLatch latch) {
        this.latch = latch;
    }

    @Override
    public Type getPayloadType(StompHeaders headers) {

        return Object.class;
    }

    @Override
    public void handleFrame(StompHeaders headers, Object payload) {
        System.out.println("接收订阅消息=" + payload);
    }

    public void handleException(StompSession session, @Nullable StompCommand command, StompHeaders headers, byte[] payload, Throwable exception) {
        exception.printStackTrace();
    }

    @Override
    public void handleTransportError(StompSession session, Throwable exception) {
        exception.printStackTrace();
        System.out.println("transport error.");
    }
}
